var that, $ = require("../../../utils/helper.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    resurl: getApp().config.resurl,
    avatar: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
   
  },

  onShow: function () {
    $.check(that)
  },
  init: function () {
    $.post("api/user/get", null, function (data) {
      that.setData({
        info: data,
        avatar:data.avatar
      })
    })
  },
  save: function (e) {
    let sub_data = e.detail.value
    sub_data.avatar = that.data.avatar
    $.post("api/user/set", sub_data,function(data){
      getApp().user_time=null
      getApp().toast("保存成功",2000,function(){
        wx.navigateBack({
          
        })
      })
    })
  },
  uploadpic: function () {
    wx.chooseImage({
      success(res) {
        let tempFilePaths = res.tempFilePaths
        $.upload("avatar", tempFilePaths[0], function (data) {
          that.setData({
            avatar: data
          })
        })
      }
    })
  }
})